package com.spaceobj.project.service.impl;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spaceobj.common.core.constant.CommonData;
import com.spaceobj.common.core.dto.SysUser;
import com.spaceobj.common.core.utils.ExceptionUtil;
import com.spaceobj.common.core.utils.RsaUtils;
import com.spaceobj.common.core.utils.SourceToTargetUtils;
import com.spaceobj.common.kafka.config.KafkaSender;
import com.spaceobj.common.kafka.constant.KafKaTopics;
import com.spaceobj.common.redis.constant.RedisKey;
import com.spaceobj.common.redis.service.RedisService;
import com.spaceobj.common.redis.service.RedissonService;
import com.spaceobj.project.bo.GetPhoneNumberBo;
import com.spaceobj.project.bo.ProjectSearchBo;
import com.spaceobj.project.component.UserClient;
import com.spaceobj.project.mapper.ProjectHelpMapper;
import com.spaceobj.project.mapper.SysProjectMapper;
import com.spaceobj.project.pojo.ProjectHelp;
import com.spaceobj.project.pojo.SysProject;
import com.spaceobj.project.pojo.SysSearchContent;
import com.spaceobj.project.service.ProjectHelpService;
import com.spaceobj.project.service.SysProjectService;
import com.spaceobj.project.service.SysSearchContentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @author zhr_java@163.com
 * @date 2022/07/23 22:00
 */
@Service
@RefreshScope
public class SysProjectServiceImpl extends ServiceImpl<SysProjectMapper, SysProject>
    implements SysProjectService {

  @Autowired private RedisService redisService;

  @Autowired private KafkaSender kafkaSender;

  @Autowired private SysProjectMapper sysProjectMapper;

  @Autowired private ProjectHelpMapper projectHelpMapper;

  @Autowired private SysSearchContentService sysSearchContentService;

  @Resource private UserClient userClient;

  @Autowired private ProjectHelpService projectHelpService;

  @Value("${privateKey}")
  private String privateKey;

  Logger LOG = LoggerFactory.getLogger(SysProjectServiceImpl.class);

  // 好友最大点击次数即可获取用户联系方式
  public static final int MAX_CLICK_SHARE_TIMES = 3;

  // 审核状态通过
  public static final int EXAMINATION_PASSED = 1;

  // 查询首页项目
  public static final int SEARCH_INDEX_PROJECT_TYPE = 0;

  // 查询我发布的项目
  public static final int SEARCH_MY_RELEASED_PROJECT = 1;

  // 属于代发项目
  public static final String DROPSHIPPING_TRUE = "1";

  @Override
  public SaResult addProject(SysProject sysProject) {

    try {
      // 校验内容是否重复
      SysProject duplicateCheck = getSysProject(sysProject);
      //
      // if (duplicateCheck != null) {
      //   return SaResult.error("请勿重复提交");
      // }

      // 校验当前提交次数是否超过最大次数
      String loginId = (String) StpUtil.getLoginId();
      SysUser sysUser = getSysUser(loginId);

      if (sysUser.getEmail().equals(CommonData.DEFAULT_EMAIL)) {
        return SaResult.error("请到个人中心设置您的邮箱");
      }

      if (sysUser.getPhoneNumber().equals(CommonData.DEFAULT_MOBILE)) {
        return SaResult.error("请到个人中心设置您的联系方式");
      }

      // if (sysUser.getReleaseProjectTimes() <= 0&&sysUser.getUserType()!="root") {
      //   return SaResult.error("今天发布次数已上线");
      // }
      // 将用户的的发布次数减少一，修改用户信息
      sysUser.setReleaseProjectTimes(sysUser.getReleaseProjectTimes() - 1);
      kafkaSender.send(sysUser, KafKaTopics.UPDATE_USER);

      // 生成UUID
      String uuid = UUID.randomUUID().toString();
      sysProject.setUuid(uuid);
      // 设置成审核中
      sysProject.setStatus(0);
      // 如果是管理员发布，不需要审核
      if (!StringUtils.isEmpty(sysUser.getUserType()) && sysUser.getUserType().equals("root")) {
        sysProject.setStatus(1);
        sysProject.setNickname(sysProject.getName());
      }

      sysProject.setIpAddress(sysUser.getIpTerritory());
      sysProject.setReleaseUserId(sysUser.getUserId());
      sysProject.setCreateTime(LocalDateTime.now());
      int result = sysProjectMapper.insert(sysProject);
      if (result == 0) {
        return SaResult.error("新增失败");
      }
      return SaResult.ok("提交成功");
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error("服务器异常");
    }
  }

  @Override
  public SaResult addProjectBySystem(SysProject sysProject) {

    try {
      // 校验内容是否重复
      SysProject duplicateCheck = getSysProject(sysProject);
      if (duplicateCheck != null) {
        return null;
      }
      // 生成UUID
      String uuid = UUID.randomUUID().toString();
      sysProject.setUuid(uuid);
      // 设置成审核中
      sysProject.setStatus(0);
      // 系统发布，不需要审核
      sysProject.setStatus(1);
      sysProject.setDropshipping("1");

      sysProject.setReleaseUserId("system");

      int result = sysProjectMapper.insert(sysProject);
      if (result == 0) {
        return SaResult.error("新增失败");
      }
      return SaResult.ok("提交成功");
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error("服务器异常");
    }
  }

  @Override
  public SaResult updateProject(SysProject sysProject) {

    try {
      if (!ObjectUtils.isEmpty(sysProject.getUuid())) {
        // 校验是否存在该项目，如果存在该项目，给checkCacheProject赋值
        SysProject project = this.getProjectByUUID(sysProject.getUuid());
        // 如果当前项目是在审核中那么返回不可重复修改
        if (ObjectUtils.isEmpty(project)) {
          return SaResult.error("项目不存在或已成交");
        }
        if (project.getStatus() == 0) {
          return SaResult.error("审核中禁止修改");
        }
        String loginId = StpUtil.getLoginId().toString();
        SysUser sysUser = getSysUser(loginId);
        if (!sysUser.getUserId().equals(project.getReleaseUserId())) {
          return SaResult.error("违规操作");
        }
        if (sysProject.getStatus() != 3) {
          // 修改的项目设置成待审核
          sysProject.setStatus(0);
        }
        // 根据项目id和version修改数据,每次修改都让版本号+1,用于处理并发修改业务
        int result = this.updateResult(sysProject);

        if (result == 0) {
          LOG.error("项目更新失败{}" + sysProject.getUuid());
          //  如果修改失败，那么根据id查询最新的版本号再次修改
          return SaResult.error("修改失败");
        }
        return SaResult.ok("提交成功");
      }
      return SaResult.error("请求错误");
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error("服务器异常");
    }
  }

  @Override
  public SaResult auditProject(SysProject project) {

    try {
      QueryWrapper<SysProject> wrapper = new QueryWrapper<>();
      wrapper.eq("p_id", project.getPId());
      SysProject sysProject = sysProjectMapper.selectOne(wrapper);
      sysProject.setStatus(project.getStatus());
      sysProject.setMessage(project.getMessage());
      int result = this.updateResult(sysProject);
      if (result == 0) {
        LOG.error("项目审核失败{}" + project.getUuid());
        return SaResult.error("审核失败");
      }
      return SaResult.ok("审核成功");
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error("审核失败,服务器异常");
    }
  }

  @Override
  public SaResult findList(ProjectSearchBo projectSearchBo) {

    try {
      SysSearchContent sysSearchContent = new SysSearchContent();
      sysSearchContent.setContent(projectSearchBo.getContent());
      sysSearchContentService.addWeight(sysSearchContent);

      if (projectSearchBo.getProjectType() == SEARCH_MY_RELEASED_PROJECT) {
        String loginId = StpUtil.getLoginId().toString();
        SysUser sysUser = getSysUser(loginId);
        projectSearchBo.setUserId(sysUser.getUserId());
      }
      List<SysProject> list = new ArrayList<>();
      // 查询首页信息
      if (projectSearchBo.getProjectType() == SEARCH_INDEX_PROJECT_TYPE) {
        String searchContent = projectSearchBo.getContent();

        QueryWrapper<SysProject> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("create_time");
        queryWrapper.eq("p_status", 1);
        if (!StringUtils.isEmpty(projectSearchBo.getContent())) {
          queryWrapper.like("p_content", projectSearchBo.getContent());
          queryWrapper.or().like("name", projectSearchBo.getName());
          queryWrapper.or().like("p_id", projectSearchBo.getContent());
          queryWrapper.or().like("p_nick_name", projectSearchBo.getContent());
          queryWrapper.or().like("p_release_user_id", projectSearchBo.getContent());
          queryWrapper.or().like("p_price", projectSearchBo.getContent());
        }

        if (projectSearchBo.getType() != null) {
          queryWrapper.eq("type", projectSearchBo.getType());
        }else {
          // 设置默认查询项目信息
          queryWrapper.eq("type", 1);
        }
        Page<SysProject> page =
            new Page<>(projectSearchBo.getCurrentPage(), projectSearchBo.getPageSize());
        IPage<SysProject> iPage = sysProjectMapper.selectPage(page, queryWrapper);
        list = iPage.getRecords();

        // 电话号码脱敏
        for (int i = 0; i < list.size(); i++) {
          list.get(i).setPhoneNumber(null);
        }
      }
      if (projectSearchBo.getProjectType() == SEARCH_MY_RELEASED_PROJECT) {
        // 查询自己发布的信息,根据项目创建人id查询项目
        QueryWrapper<SysProject> queryWrapper = new QueryWrapper<>();
        queryWrapper
            .eq("p_release_user_id", projectSearchBo.getUserId())
            .ne("p_status", 3)
            .orderByDesc("create_time");
        Page<SysProject> page =
            new Page<>(projectSearchBo.getCurrentPage(), projectSearchBo.getPageSize());
        IPage<SysProject> iPage = sysProjectMapper.selectPage(page, queryWrapper);
        list = iPage.getRecords();
      }
      return SaResult.ok().setData(list);
    } catch (NotLoginException e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error(e.getMessage());
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error("项目列表查询结果异常");
    }
  }

  @Override
  public SaResult queryListAdmin(ProjectSearchBo projectSearchBo) {

    try {
      List<SysProject> list;
      QueryWrapper<SysProject> queryWrapper = new QueryWrapper<>();
      queryWrapper.orderByDesc("create_time");
      if (!StringUtils.isEmpty(projectSearchBo.getContent())) {
        queryWrapper.like("p_content", projectSearchBo.getContent());
        queryWrapper.or().like("p_id", projectSearchBo.getContent());
        queryWrapper.or().like("p_nick_name", projectSearchBo.getContent());
        queryWrapper.or().like("p_release_user_id", projectSearchBo.getContent());
      }
      Page<SysProject> page =
          new Page<>(projectSearchBo.getCurrentPage(), projectSearchBo.getPageSize());
      IPage<SysProject> iPage = sysProjectMapper.selectPage(page, queryWrapper);
      list = iPage.getRecords();
      return SaResult.ok().setData(list);
    } catch (RuntimeException e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error("服务器异常");
    }
  }

  @Override
  public void addPageViews(String uuid) {

    try {
      SysProject sysProject = this.getProjectByUUID(uuid);
      sysProject.setPageViews(sysProject.getPageViews() + 1);
      int result = this.updateResult(sysProject);
      if (result == 0) {
        LOG.error("项目UUID：{}" + sysProject.getUuid() + "浏览次数添加失败");
      }
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      LOG.error("add Page view error", e.getMessage());
    }
  }

  /**
   * 根据项目id更新
   *
   * @param sysProject
   * @return
   */
  public int updateResult(SysProject sysProject) {
    QueryWrapper<SysProject> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("p_id", sysProject.getPId());
    sysProject.setVersion(sysProject.getVersion() + 1);
    int result = sysProjectMapper.update(sysProject, queryWrapper);
    return result;
  }

  @Override
  public SaResult getPhoneNumberByProjectId(GetPhoneNumberBo getPhoneNumberBo) {

    try {
      String loginId = (String) StpUtil.getLoginId();
      SysUser sysUser = getSysUser(loginId);
      getPhoneNumberBo.setUserId(sysUser.getUserId());
      SysProject sysProject = this.getProjectByUUID(getPhoneNumberBo.getUuid());
      if (ObjectUtils.isEmpty(sysProject)) {
        return SaResult.error("项目不存在或已成交");
      }
      // 如果项目发布人id和userId相同，直接返回用户联系方式
      if (sysProject.getReleaseUserId().equals(getPhoneNumberBo.getUserId())) {
        // 如果是代发，那么返回项目的电话号
        if (sysProject.getDropshipping().equals(DROPSHIPPING_TRUE)) {
          return SaResult.ok().setData(sysProject.getPhoneNumber());
        }
        return SaResult.ok().setData(sysUser.getPhoneNumber());
      }

      //  判断项目是否审核通过
      if (sysProject.getStatus() != EXAMINATION_PASSED) {
        return SaResult.error("项目未通过审核");
      }

      // 判断资源类型是否是国家招标项目，如果是国家招标项目直接返回结果
//      if(sysProject.getType()==1){
//        return SaResult.ok().setData(sysProject.getPhoneNumber());
//      }

      // 如果是福利 则不需要看广告
//      if(sysProject.getType()==10){
//        return SaResult.ok().setData(sysProject.getPhoneNumber());
//      }

      // 判断该用户的助力列表中是否有该项目数据，当前方案要保证项目助力hash表的RedisKey永不失效
      // 判断是否已经获取到该项目联系人
      ProjectHelp helpBo =
          this.getProjectHelpLink(getPhoneNumberBo.getUuid(), getPhoneNumberBo.getUserId());
      if (!ObjectUtils.isEmpty(helpBo)) {
        if (helpBo.getHpStatus() == EXAMINATION_PASSED
            || helpBo.getHpNumber() >= MAX_CLICK_SHARE_TIMES) {
          // 如果是代发项目，直接返回联系方式
          if (sysProject.getDropshipping().equals(DROPSHIPPING_TRUE)) {
            return SaResult.ok().setData(sysProject.getPhoneNumber());
          }

          // 获取项目发布者id的联系方式,后期此处修改成根据账户获取用户信息，项目中的userId设置成email,数据进行脱敏
          String releaseId = sysProject.getReleaseUserId();
          SysUser releaseProjectUser = this.getSysUserByUserId(releaseId);
          System.out.println(releaseProjectUser);
          // //  判断当前用户是否已经实名认证
          // if (sysUser.getRealNameStatus() != 1) {
          //   return SaResult.error("实名认证后获取");
          // }
          return SaResult.ok().setData(releaseProjectUser.getPhoneNumber());
        }
      }

      // 判断用户的邀请值大于0
      if (sysUser.getInvitationValue() > 0) {
        //  邀请值减一，如果项目助力列表中没有该项目，那么设置成已经获取到，如果没有，那么新增到项目助力列表并设置成已经获取到的状态
        sysUser.setInvitationValue(sysUser.getInvitationValue() - 1);
        if (!ObjectUtils.isEmpty(helpBo)) {
          helpBo.setHpNumber(MAX_CLICK_SHARE_TIMES);
          helpBo.setHpStatus(1);
          if (sysProject.getDropshipping().equals(DROPSHIPPING_TRUE)) {
            helpBo.setDropshipping(DROPSHIPPING_TRUE);
          }
          // 更新该用户助力的项目助力信息

          kafkaSender.send(helpBo, KafKaTopics.UPDATE_HELP_PROJECT);
        } else {
          helpBo =
              ProjectHelp.builder()
                  .hpId(UUID.randomUUID().toString())
                  .pUUID(sysProject.getUuid())
                  .createUserId(getPhoneNumberBo.getUserId())
                  .hpNumber(MAX_CLICK_SHARE_TIMES)
                  .pContent(sysProject.getContent())
                  .pPrice(sysProject.getPrice())
                  .pReleaseUserId(sysProject.getReleaseUserId())
                  .hpStatus(1)
                  .projectId(sysProject.getPId())
                  .name(sysProject.getName())
                  .hpCreateNickName(sysUser.getNickName())
                  .ipTerritory(sysProject.getIpAddress())
                  .projectCreateNickName(sysProject.getNickname())
                  .dropshipping(sysProject.getDropshipping())
                  .build();
          if (sysProject.getDropshipping().equals(DROPSHIPPING_TRUE)) {
            helpBo.setDropshipping(DROPSHIPPING_TRUE);
          }
          // 通知项目助力服务该用户新增一条获取成功的项目助力信息
          kafkaSender.send(helpBo, KafKaTopics.ADD_HELP_PROJECT);
        }

        //  判断当前用户是否已经实名认证
        // if (sysUser.getRealNameStatus() != 1) {
        //   return SaResult.error("实名认证后获取");
        // }

        // 通知用户服务更新该用户的基本信息
        kafkaSender.send(sysUser, KafKaTopics.UPDATE_USER);

        if (sysProject.getDropshipping().equals(DROPSHIPPING_TRUE)) {
          return SaResult.ok().setData(sysProject.getPhoneNumber());
        }

        String releaseId = sysProject.getReleaseUserId();
        SysUser releaseProjectUser = this.getSysUserByUserId(releaseId);

        return SaResult.ok().setData(releaseProjectUser.getPhoneNumber());
      }
      // 如果已经分享过，提示还差多少好友点击
      if (!ObjectUtils.isEmpty(helpBo)) {
        int num = (int) (MAX_CLICK_SHARE_TIMES - helpBo.getHpNumber());
        return SaResult.error("还差" + num + "位好友点击").setCode(202);
      }

      // 需要获取助力链接
      return SaResult.error("分享好友或看广告获取").setCode(202);
    } catch (Exception e) {

      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return SaResult.error("服务器异常");
    }
  }

  /**
   * 获取待审核项目的数量
   *
   * @return
   */
  @Override
  public SaResult getPendingReview() {

    QueryWrapper<SysProject> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("p_status", 0);
    List<SysProject> sysProjectList = sysProjectMapper.selectList(queryWrapper);
    return SaResult.ok().setData(sysProjectList.size());
  }

  @Override
  public SysProject getProjectByUUID(String uuid) {
    SysProject sysProject = null;
    try {
      QueryWrapper<SysProject> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("p_uuid", uuid);
      sysProject = sysProjectMapper.selectOne(queryWrapper);
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return null;
    }
    return sysProject;
  }

  @Override
  public String getPhoneNumberByProjectUUID(String uuid) {

    String phoneNumber = null;
    ProjectHelp projectHelp = null;

    String loginId = (String) StpUtil.getLoginId();
    SysUser sysUser = getSysUser(loginId);

    // 每日广告流量次数上限，请分享好友获取
    if (sysUser.getViewVideoAdvertiseTimes() == 0) {
      return "今天浏览广告次数上限！";
    }
    // 修改用户广告浏览次数减一
    sysUser.setViewVideoAdvertiseTimes(sysUser.getViewVideoAdvertiseTimes() - 1);
    kafkaSender.send(sysUser, KafKaTopics.UPDATE_USER);

    QueryWrapper<SysProject> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("p_uuid", uuid);
    SysProject sysProject = sysProjectMapper.selectOne(queryWrapper);
    // 判断项目助力是否存在，存在则更新，不存在就新增
    projectHelp = projectHelpService.getProjectHelpLink(uuid, sysUser.getUserId());
    LOG.info("projectHelp:{}", projectHelp);
    LOG.info("sysUser:{}", sysUser);
    LOG.info("sysProject:{}", sysProject);

    if (ObjectUtils.isEmpty(projectHelp)) {

      projectHelp =
          ProjectHelp.builder()
              .hpId(UUID.randomUUID().toString())
              .projectId(sysProject.getPId())
              .pUUID(sysProject.getUuid())
              .hpNumber(3)
              .createUserId(sysUser.getUserId())
              .hpCreateNickName(sysUser.getNickName())
              .pContent(sysProject.getContent())
              .pPrice(sysProject.getPrice())
              .pReleaseUserId(sysProject.getReleaseUserId())
              .hpStatus(1)
              .ipTerritory(sysProject.getIpAddress())
              .projectCreateNickName(sysProject.getNickname())
              .build();
      SourceToTargetUtils.copyNotNullProperties(sysProject, projectHelp);
      projectHelpMapper.insert(projectHelp);
    }

    if (!ObjectUtils.isEmpty(projectHelp)) {
      projectHelp.setHpStatus(1);
      projectHelp.setHpNumber(3);
      projectHelpService.updateProjectHelp(projectHelp);
    }

    if (sysProject.getDropshipping().equals(DROPSHIPPING_TRUE)) {
      phoneNumber = sysProject.getPhoneNumber();
    }
    if (!sysProject.getDropshipping().equals(DROPSHIPPING_TRUE)) {
      SysUser releaseUser = getSysUserByUserId(sysProject.getReleaseUserId());
      phoneNumber = releaseUser.getPhoneNumber();
    }

    return phoneNumber;
  }

  @Override
  public SysProject getSysProject(SysProject sysProject) {
    QueryWrapper<SysProject> queryWrap = new QueryWrapper<>();
    queryWrap.like("name", sysProject.getName());
    SysProject sysProjectSearch = sysProjectMapper.selectOne(queryWrap);
    return sysProjectSearch;
  }

  /**
   * 根据账户获取用户信息，异常则返回null
   *
   * @param account
   * @return
   * @throws InterruptedException
   */
  public SysUser getSysUser(String account) {

    SysUser sysUser = null;
    try {
      boolean flag = redisService.hasKey(RedisKey.SYS_USER_LIST);
      if (flag) {
        sysUser = redisService.getCacheMapValue(RedisKey.SYS_USER_LIST, account, SysUser.class);
        if (!ObjectUtils.isEmpty(sysUser)) {
          return sysUser;
        }
      }
      Object res = userClient.getUserInfoByAccount(account);
      sysUser = RsaUtils.decryptByPrivateKey(res, SysUser.class, privateKey);
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return null;
    }
    return sysUser;
  }

  public SysUser getSysUserByUserId(String userId) {

    SysUser sysUser = null;
    try {
      boolean flag = redisService.hasKey(RedisKey.SYS_USER_LIST);
      if (flag) {
        List<SysUser> sysUserList =
            redisService.getHashMapValues(RedisKey.SYS_USER_LIST, SysUser.class);
        List<SysUser> resultSysUserList =
            sysUserList.stream()
                .filter(
                    u -> {
                      return !ObjectUtils.isEmpty(u) && u.getUserId().equals(userId);
                    })
                .collect(Collectors.toList());
        if (resultSysUserList.size() > 0) {
          return resultSysUserList.get(0);
        }
      }
      Object res = userClient.getSysUserByUserId(userId);
      sysUser = RsaUtils.decryptByPrivateKey(res, SysUser.class, privateKey);
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return null;
    }
    return sysUser;
  }

  public ProjectHelp getProjectHelpLink(String pUUID, String userId) {

    ProjectHelp projectHelp = null;
    try {
      projectHelp = projectHelpService.getProjectHelpLink(pUUID, userId);
    } catch (Exception e) {
      ExceptionUtil.exceptionToString(e);
      e.printStackTrace();
      return null;
    }
    return projectHelp;
  }
}
